// pages/home/home.js
import Shangping from "./model.js";
let obj = new Shangping();
Page({

  clifun:function(){
      
  },
  data: {
    goods: [],
  },
  addcart:function(e){
    this.setData({
      toastHidden: false
    }); 
    for (var i in this.data.goods) {
      if (this.data.goods[i].id == e.target.id){
        var z =parseInt(i)+1;
        wx.request({
          url: 'http://local.xiaochengxu.com/api/vi/shangping',
          data:{id:z},
          method: 'POST',
          success: function (res) {
            if(res.data==0){
              wx.showToast({
                title: '请不要重新添加',
                icon: 'loading',
                duration: 3000,
              });
            }else{
              wx.showToast({
                title: '加入购物车成功',
                icon: 'success',
                duration: 3000,
              });
            }
          }
        })
      }
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    obj.getList(this);
  }

 
})